//
//  AIUserInfoManager.m
//  MiaMind
//
//  Created by Vill on 2023/11/24.
//

#import "AIUserInfoManager.h"
#import "AIUserDataManager.h"

@implementation AIUserInfoManager

///单例
+ (instancetype)shareManager{
    static dispatch_once_t onceToken;
    static AIUserInfoManager *manager;
    dispatch_once(&onceToken, ^{
        manager = [[AIUserInfoManager alloc]init];
        [manager fillWithLocalData];
    });
    return manager;
}

-(void)fillWithLocalData{
    AIUserInfoModel *model = [AIUserDataManager loadLocalWithKey:userInfoSavePath catcheType:LocalDataToolsSaveType_Library];
    if (model) {
        _userInfo = model;
    } else {
        _userInfo = [AIUserInfoModel new];
    }
}

/// 更新用户信息
- (void)updateUserInfo:(AIUserInfoModel *)model{
    [AIUserDataManager saveLoacalDataWithKey:userInfoSavePath object:model catheType:LocalDataToolsSaveType_Library];
    [self fillWithLocalData];
//    [[NSNotificationCenter defaultCenter] postNotificationName:UserInfoUpdateNot object:nil];
}

/// 清除用户信息
- (void)clearUserInfo{
    [AIUserDataManager deleteLoacalWithKey:userInfoSavePath catheType:LocalDataToolsSaveType_Library];
    _userInfo = [AIUserInfoModel new];
}

@end
